<template>
  <div class="address">
    <van-nav-bar
      title="我的收货地址"
      left-text="返回"
      right-text="新增地址"
      left-arrow
      @click-left="$router.push('/index/mine')"
      @click-right="$router.push('/newaddress')"
    />

    <!-- 列表 -->
    <div class="addlist" v-for="(item, index) in address_list" :key="index">
      <div class="add_left">
        <div class="myadd">{{ item.address }}</div>
        <div class="name">
          <span>{{ item.name }}</span>
          <span>{{ item.phone }}</span>
        </div>
      </div>
      <div class="madd" @click="madd(item)">修改</div>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import { address_list } from "../utils/api";
export default {
  data() {
    return {
      address_list: [],
      userid: JSON.parse(localStorage.getItem("userinfo")).id,
    };
  },
  mounted() {
    address_list({ userid: this.userid }).then((res) => {
      this.address_list = res.data.list;
    });
  },
  methods: {
    ...mapActions(["request_address_list"]),
    madd(item) {
      let info = JSON.stringify(item);
      this.$router.push("/modifyaddress/" + info);
    },
  },
};
</script>
<style lang="scss" scoped>
.addlist {
  margin: 10px 20px;
  display: flex;
  .add_left {
    flex: 1;
    display: flex;
    flex-direction: column;
    .myadd {
      font-size: 18px;
      font-weight: bold;
    }
    .name {
      font-size: 14px;
      color: #999;
      line-height: 30px;
    }
  }
  .madd {
    width: 60px;
    text-align: center;
    line-height: 60px;
  }
}
</style>